<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="stylesheet" type="text/css" href="http://unpkg.com/view-design/dist/styles/iview.css"> -->
    <script type="text/javascript" src="./vue.js"></script>
    <title>组件详解</title>
</head>
<body>
<h2>单个slot</h2>
<div id="app">

    <my-component>
        <p>分发的内容</p>
        <p>更多分发的内容</p>
    </my-component>

</div>
<h2>具名Slot</h2>
<div id="app2">
    <my-child>
        <h2 slot="header">标题</h2>
        <p>我是正文</p>
        <div slot="footer">底部信息</div>
    </my-child>
</div>
<h2>作用域插槽</h2>
<div id="app3">
    <child-component>
        <template scope="props">
            <p>来自父组件的内容</p>
            <p>{{props.msg}}</p>
        </template>
    </child-component>
</div>
<script>

    var childApp3 = {
        template:'<div><slot msg="来自子组件的内容"></slot></div>'
    }
    var app3 = new Vue({
        el:'#app3',
        components:{
           'child-component':childApp3
        }
    });


    var app2Child = {
        template:'<div><div class="header"><slot name="header"></slot></div>' +
            '<div class="main"><slot></slot></div>' +
            '<div class="footer"><slot name="footer"></slot></div></div>',
            mounted:function(){
            var header = this.$slots.header;
            var main = this.$slots.default;
            var footer = this.$slots.footer;
            console.log(footer);
        }
    }
    var app = new Vue({
        el:'#app2',
        components:{
            'my-child':app2Child
        },
       
    });



    Vue.component('my-component',{
        template:'<div><slot><p>如果父组件没有插入内容，我将作为默认出现</p></slot></div>'
    });
    var app = new Vue({
        el:'#app'
    });
</script>
</body>
</html>